package com.cedifie.lendapp.ui.loan.impl

import com.cedifie.lendapp.http.ApiService
import com.cedifie.lendapp.http.ApiService.addCommonParams
import com.cedifie.lendapp.http.HttpHelper
import com.cedifie.lendapp.http.IHttpCallback
import org.json.JSONObject

/**
 * Cedifie
 * @Author wwdeng
 * @CreateTime: 2024/6/17 13:45
 * @Annotation：审核中、拒绝、放贷中、放贷中法语 Model 实现
 */
class CedLoanCommonModelImpl {

    /**
     * 获取贷款信息
     */
    fun loadCedLoanInfoAction(callBack: IHttpCallback){
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.CED_API_COMMON_URL)
        val params = JSONObject().addCommonParams().apply {
            put("path", ApiService.API_PATH.CED_API_LOAN_APPLY_PATH)
        }
        HttpHelper.postCedAction(httpUrl,params,callBack)
    }

    /**
     * 获取绑定的账户列表
     */
    fun loadCedLoanAccountAction(callBack: IHttpCallback){
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.CED_API_COMMON_URL)
        val params = JSONObject().addCommonParams().apply {
            put("path", ApiService.API_PATH.CED_API_ACCOUNT_LIST_PATH)
        }
        HttpHelper.postCedAction(httpUrl,params,callBack)
    }

    /**
     * 提交绑卡
     */
    fun submitCedBindAccountAction(mobile: String, walletChannel: String, bindFlag:String,callBack: IHttpCallback){
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.CED_API_COMMON_URL)
        val params = JSONObject().addCommonParams().apply {
            put("path", ApiService.API_PATH.CED_API_ACCOUNT_ADD_PATH)
            put("walletMobile", mobile)
            put("walletMobileConfirm", mobile)
            put("walletChannel", walletChannel)
            put("addBindFlag", bindFlag)
        }
        HttpHelper.postCedAction(httpUrl, params, callBack)
    }

    /**
     * 删除账户
     */
    fun deleteCedAccountAction(ids: String,callBack: IHttpCallback) {
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.CED_API_COMMON_URL)
        val params = JSONObject().addCommonParams().apply {
            put("path", ApiService.API_PATH.CED_API_ACCOUNT_DELETE_PATH)
            put("ids", ids)
        }
        HttpHelper.postCedAction(httpUrl, params, callBack)
    }

    /**
     * 是否需要显示清除账号信息按钮、清除账户数据
     */
    fun clearUserDataAction(isShowButton: Boolean,callBack: IHttpCallback){
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.CED_API_COMMON_URL)
        val params = JSONObject().addCommonParams().apply {
            put("path", ApiService.API_PATH.CED_API_USER_DATA_CLEAR_PATH)
        }
        if (isShowButton){
            params.put("type","GET")
        } else {
            params.put("type","DROP")
        }
        HttpHelper.postCedAction(httpUrl, params, callBack)
    }
}